;*****************************************************************	
		;;***WRITTEN BY BADR GROUP**
		;;***ENG Ahmad Fayed&Ahmad ELalfy&Mohamad ELmelegy&Mohamad ELnewehy&Mostafa ELsamragy***
               	;;***DISCRIBTION:COUNTER(AUTO)BESIDES CONTROLLING DC MOTOR USING 16F84A&(1)7SEGMENT INCRESING&DECREASING&HOLD&MAKE IT ZREO BY 4 SWITCHS*** 
		;;***ZERO BY HOLD SWITCH THEN IN SAME TIME PRESS MCLR SWITCH
TIMER1 EQU 0C
TIMER2 EQU 0D
MOTOR EQU 0E
LIST P=16F84A
#INCLUDE<P16F84A.INC>
		BSF STATUS,5
		MOVLW B'00000111'	
		MOVWF TRISA
		CLRF TRISB
		MOVLW B'10001000'
		MOVWF OPTION_REG
		BCF STATUS,5
		CLRF TIMER1
		CLRF MOTOR
		CLRF TIMER2
		GOTO LOOP
	;;SUP
HARD1		INCF MOTOR,1
		MOVLW B'00000011'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL RIGHT
		MOVLW B'00001010'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL ZERO
		MOVLW B'00001101'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL LEFT
		MOVLW B'00010100'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL ZERO1
	RETURN
HARD2		INCF MOTOR,1
		MOVLW B'00000011'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL LEFT
		MOVLW B'00001010'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL ZERO
		MOVLW B'00001101'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL RIGHT
		MOVLW B'00010100'
		SUBWF MOTOR,0
		BTFSC STATUS,2
		CALL ZERO1
	RETURN	
RIGHT		BSF PORTA,3
		BCF PORTA,4
	RETURN
LEFT		BCF PORTA,3
		BSF PORTA,4
	RETURN
ZERO		BCF PORTA,3
	 	BCF PORTA,4
	RETURN
ZERO1		BCF PORTA,3
		BCF PORTA,4
		CLRF MOTOR
	RETURN
SEC		MOVLW .35
		MOVWF TIMER2
DELAY		SLEEP
		CALL LOOP
		DECFSZ TIMER2,1
		GOTO DELAY
	RETURN
DIS1		MOVF TIMER1,0
		CALL PTRN1
		MOVWF PORTB
	RETURN
AA1		CLRF TIMER1
		GOTO ACTION1
AA2		MOVLW B'00001000'
		MOVWF TIMER1
		GOTO GG
AA3		MOVLW B'00001001'
		MOVWF TIMER1
		GOTO GG
PTRN1		ADDWF PCL,1
		RETLW B'11111100';1
		RETLW B'00010010';2		
		RETLW B'00011000';3
		RETLW B'00101100';4
		RETLW B'00001001';5
		RETLW B'00000001';6	
		RETLW B'11011100';7
		RETLW B'00000000';8
		RETLW B'00001000';9
		RETLW B'01000000';0
LOOP   		SLEEP
SW1		BTFSS PORTA,0
		GOTO MM1
SW2		BTFSS PORTA,1
		GOTO MM2
SW4		BTFSS PORTA,2
		GOTO SW44
	RETURN
SW44		MOVF TIMER1,1
		CALL DIS1
		CALL LOOP
		GOTO SW44
MM1		CALL ZERO1
		CALL LOOP
		GOTO ACTION1
MM2		CALL ZERO1
		CALL LOOP
		GOTO ACTION2
ACTION1		CALL LOOP
        	CALL DIS1
		CALL SEC
		CALL HARD1
		CALL LOOP
		INCF TIMER1,1		
		BTFSS TIMER1,1
		GOTO ACTION1
		BTFSS TIMER1,3
		GOTO ACTION1
		GOTO AA1
ACTION2		CLRW
		ADDWF TIMER1,1
		BTFSC STATUS,2
		GOTO AA2
		GOTO BB
GG		CALL LOOP
		CALL DIS1
		CALL SEC
		CALL HARD2 
		CALL LOOP 	
		DECF TIMER1,1
BB		BTFSS TIMER1,0
		GOTO GG
		BTFSS TIMER1,1
		GOTO GG
		BTFSS TIMER1,2
		GOTO GG
		BTFSS TIMER1,3
		GOTO GG
		GOTO AA3
END	
